

import {canvasClip, globalCtx, px, watchValueChange, winH, winW} from '../libs/utils.js';
import Group from "./group";
import TextStroke from "./text_stroke";
import Img from "./img";
import TextAnim from "./text_anmi";


/// 文本+图片 组成的 对话框容器
export default class DialogText extends Group {
    /**
     *
     * @param imgSrc 弹窗背景图片
     * @param x     弹窗起点x
     * @param y     弹窗起点y
     * @param width 背景图片宽
     * @param height 背景图片高
     * @param content 文字
     * @param textStartX 文字起点x
     * @param textStartY 文字起点y
     */
    constructor(imgSrc,x, y, width, height,content,textStartX,textStartY) {
        super();
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.dialogBg = new Img(imgSrc,x, y, width, height);
        this.addChild(this.dialogBg, "dialogBg")

        this.textDialog = new TextAnim(content,textStartX,textStartY,px(26) );
        this.textDialog.maxWidth = width -(textStartX-x)-5;
        this.textDialog.textWrap = true;
        this.textDialog.color = '#000';
        this.addChild(this.textDialog,"textDialog")

        watchValueChange(this, 'content', (val) => {
            this.resize();
        });
    }
    /**
     * 重新设置参数
     */
    resize() {
        this.textDialog.textIndex = 0
        this.textDialog.content = this.content;

    }

}